package com.code.coinprice.controllers;

import com.code.coinprice.handlers.RedisHandler;
import com.code.coinprice.models.PushMessage;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Set;

@RestController
@RequestMapping("/redis")
public class RedisController {

    @Resource
    private RedisHandler redisHandler;

    @PostMapping("/zet")
    public void zsetAdd(@RequestBody PushMessage pushMessage) {
        redisHandler.zsetAdd(pushMessage.getPushMsg(), pushMessage.getClientChannelId(), 1);
    }

    @GetMapping("/zet")
    public Set<Object> zsetList(@Param("source") String source) {
        return redisHandler.zgetRange(source, 0, -1);
    }

    @DeleteMapping("/zet")
    public void zsetDelete(@Param("source") String source,
                           @Param("clientChannelId") String clientChannelId) {
        // Object[] str = new Object[1];
        // str[0] = clientChannelId;
        redisHandler.zsetRemove(source, clientChannelId);
    }

}
